package com.sskj.qiangjin.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.bean.UserBean;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.qiangjin.bean.CommonBean;
import com.sskj.qiangjin.bean.OpenAwardBean;
import com.sskj.qiangjin.http.HttpConfig;
import com.sskj.qiangjin.ui.fragment.QiangjinFragment;


public class QiangjinFragmentPresenter extends BasePresenter<QiangjinFragment> {

    public void getUserInfo() {
        httpService.userInfo("pb")
                .tag(this)
                .execute(new JsonCallBack<HttpData<UserBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<UserBean>> response) {
                        HttpData httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            UserBean userBean = (UserBean) httpData.getData();
                            mView.updateUser(userBean);
                        }
                    }
                });
    }


    /**
     * 普通用户下注
     */
    public void normalBet(String type, String money, String escape_beishu) {
        httpService.normalBet(type, money, escape_beishu)
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            ToastUtil.showShort(httpData.msg);
                            mView.betSuccess(type, money, escape_beishu);
                        } else {
                            ToastUtil.showShort(httpData.msg);
                            mView.betFail();
                        }
                    }
                });
    }


    /**
     * 普通用户逃跑
     */
    public void normalRun() {
        httpService.normalRun()
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.msg);
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.runSuccess();

                        }
                    }
                });
    }

    /**
     * 公共数据
     */
    public void getCommonData() {
        httpService.getCommonData()
                .tag(this)
                .execute(new JsonCallBack<HttpData<CommonBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<CommonBean>> response) {
                        HttpData httpData = response.body();
//                        ToastUtil.showShort(httpData.msg);
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updataUI((CommonBean) httpData.getData());

                        }
                    }
                });
    }

    /**
     * 开奖历史列表取前5展示
     */
    public void getOpenAwardList(String account) {
        httpService.openAwardList(account, 1, 10)
                .tag(this)
                .execute(new JsonCallBack<HttpData<PageBean<OpenAwardBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<PageBean<OpenAwardBean>>> response) {
                        HttpData httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updataAwardHistory(response.body().getData().getList());
                        }
                    }
                });
    }


}
